home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / impr_dev.idb / usr / impressario / src / examples / libimp / impverbatim.c.z / impverbatim.c
Encoding:
C/C++ Source or Header  |  1997-07-30  |  3.3 KB  |  131 lines

  1. /**************************************************************************
  2.  *
  3.  *           Copyright (c)    1993 Silicon Graphics, Inc.
  4.  *            All Rights Reserved
  5.  *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  7.  *
  8.  * The copyright notice above does not evidence any actual of intended
  9.  * publication of such source code, and is an unpublished work by Silicon
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly
  13.  * prohibited.
  14.  *
  15.  * RESTRICTED RIGHTS LEGEND:
  16.  *
  17.  * Use, duplication or disclosure by the Government is subject to
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311
  24.  **************************************************************************
  25.  *
  26.  * File: impverbatim.c
  27.  *
  28.  * Description: Converts an SGI Image file to VERBATIM storage format.
  29.  *
  30.  *    Uasge: impverbatim inimage outimage
  31.  *
  32.  **************************************************************************/
  33.  
  34.  
  35. #ident "$Revision: 1.1 $"
  36.  
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include "imp.h"
  42.  
  43.  
  44. /**************************************************************************
  45.  *
  46.  * Function: main
  47.  *
  48.  * Description: Program entry point
  49.  *
  50.  * Parameters: 
  51.  *    argc (I) - number of command line arguments
  52.  *    argv (I) - command line arguments
  53.  *
  54.  * Return: 0 if no errors. 1 if errors.
  55.  *
  56.  **************************************************************************/
  57.  
  58. int main(int argc, char *argv[])
  59. {
  60.     IMPImage *inImage, *outImage;
  61.     register int y, chan;
  62.     register int ysize, numChan;
  63.     short *rowbuf;
  64.     char *pname;
  65.  
  66.     /*
  67.      * Extract the program name
  68.      */
  69.     pname = ((pname = strrchr(argv[0], '/')) == NULL) ? argv[0]: pname + 1;
  70.  
  71.     /*
  72.      * Check the arg count
  73.      */
  74.     if (argc < 3) {
  75.     fprintf(stderr, "Usage: %s inimage outimage\n", pname);
  76.     exit(1);
  77.     } 
  78.  
  79.     /*
  80.      * Open the input image and the output image
  81.      */
  82.     if ((inImage = impOpen(argv[1], "r")) == NULL ) {
  83.     impPerror(pname);
  84.     exit(1);
  85.     }
  86.     rowbuf = (short*)malloc(impXSize(inImage) * sizeof(short));
  87.     ysize = impYSize(inImage);;
  88.     numChan = impNumChannels(inImage);
  89.     if ((outImage = impOpen(argv[2], "w",
  90.         impMakeRasterType(IMP_RASTER_ENC_VERBATIM, impRasterBPP(inImage)),
  91.         impDimension(inImage),
  92.         impXSize(inImage),
  93.         ysize,
  94.         numChan,
  95.         impImageType(inImage),
  96.         impName(inImage))) == NULL) {
  97.     impPerror(pname);
  98.     exit(1);
  99.     }
  100.  
  101.     /*
  102.      * Convert the image
  103.      */
  104.     for (chan = 0; chan < numChan; chan++)
  105.     for (y = 0; y < ysize; y++) {
  106.         if (impReadRow(inImage, rowbuf, y, chan) < 0) {
  107.         impPerror(pname);
  108.         exit(1);
  109.         }
  110.         if (impWriteRow(outImage, rowbuf, y, chan) < 0) {
  111.         impPerror(pname);
  112.         exit(1);
  113.         }
  114.     }
  115.  
  116.     /*
  117.      * Close up all images and free storage
  118.      */
  119.     free(rowbuf);
  120.     if (impClose(inImage) < 0) {
  121.     impPerror(pname);
  122.     exit(1);
  123.     }
  124.     if (impClose(outImage) < 0) {
  125.     impPerror(pname);
  126.     exit(1);
  127.     }
  128.  
  129.     return 0;
  130. }
  131.